<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
</head>
<body>
	<div class="content-info py-5">
        <input type="button" name="create" id="create" value="开户" onclick="createUser()"/>
	    <input type="button" name="show" id="show" value="删户" onclick="showHidden()" />
	    <input type="button" name="show" id="show" value="账户管理" onclick="check_account()" />
    </div>
    <div>
        <p id="delete_table">

        </p>
    </div>
	<script>
        function getCookie(cookieName) {
            const strCookie = document.cookie
            const cookieList = strCookie.split(';')
            for(let i = 0; i < cookieList.length; i++) {
                const arr = cookieList[i].split('=')
                if (cookieName === arr[0].trim()) {
                    return arr[1];
                }
            }
            return ''
        }
		function createUser(){
			window.location.href="register.html"
		}
        function showHidden(){
            document.getElementById("delete_table").innerHTML = 
            '<form action="#" method="post">' +
            '    <input type="text" name="bankcard" id="bankcard" placeholder="请输入银行卡号"/></br></br>' + 
            '    <input type="button" name="delete" id="delete" value="删户" onclick="deleteUser()"/>' +
            '</form>'
        }
        function deleteUser(){
            // 打开http post请求
            var url = "http://139.9.84.117:5000/account/delete";
            var httpRequest = new XMLHttpRequest();
		httpRequest.withCredentials = true;
            httpRequest.open('POST', url, true);
            httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            // 获取银行卡号
            var bankcard = document.getElementById("bankcard");
            var objStr = "uid=" + bankcard.value;
            httpRequest.send(objStr);
            // 回调函数
            httpRequest.onreadystatechange = function(){
                if(httpRequest.readyState == 4 && httpRequest.status == 200){
                    var responseText = httpRequest.responseText;
                    if(responseText == "success"){
                        alert("删户成功！");
                        document.getElementById("delete_table").innerHTML = '';
                    } else {
                        alert(responseText);
                    }
                }
            }
        }
		function check_account(){
			window.location.href="account.html"
		}
	</script>
</body>
</html>
